package com.itheima.socket.udp.demo03;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class SendDataThread implements Runnable {


    @Override
    public void run() {

        try {
            while (true) {
                DatagramSocket datagramSocket = new DatagramSocket();
                Scanner scanner = new Scanner(System.in);
                String next = scanner.next();
                byte[] bytes = next.getBytes();
                int length = bytes.length;
                InetAddress inetAddress = InetAddress.getByName("255.255.255.255");
                int port = 7777;
                DatagramPacket datagramPacket = new DatagramPacket(bytes, length, inetAddress, port);
                datagramSocket.send(datagramPacket);
                datagramSocket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
